<%-- 
    Document   : tukar_kata_laluan
    Created on : Oct 31, 2012, 11:34:07 PM
    Author     : fikri
--%>
<%@ include file="/WEB-INF/jsp/include/page_header.jspf" %>
<%@page contentType="text/html" pageEncoding="windows-1252"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>.: THIS :.</title>
        <script type="text/javascript">
            $(document).ready(function(){
                $('.tukar_laluan').submit( function () {
                    var hasError = false;
                    $('.error').text('');
//                    var passbookVal = $("#passbook").val();
                    var passwordVal = $("#password").val();
                    var checkVal = $("#password-check").val(); 
                    var oldPass = $("#oldPassword").val();
//                    if(passbookVal== ''){
//                        $("#passbook").after('<span class="error">Sila masukan no. buku akaun</span>');
//                        hasError = true;
//                    }else 
                                     
                    if (oldPass === '') {
                            $("#oldPassword").after('<span class="error">Sila masukan kata laluan lama.</span>');
                        hasError = true;
                    } else if (passwordVal == '') {
                            $("#password").after('<span class="error">Sila masukan kata laluan.</span>');
                        hasError = true;
                    } else if (checkVal == '') {
                        $("#password-check").after('<span class="error">Sila masukan kata laluan.</span>');
                        hasError = true;
                    } else if (passwordVal != checkVal ) {
                        $("#password-check").after('<span class="error">Kata Laluan tidak sama.</span>');
                        hasError = true;
                    }
                    if(hasError == true) {
                        return false;
                    } else {
                        blockUI();
                    }
                    
                }); 
            });
            
            function validateForm(f) {
                 
                     res1 = /[a-zA-Z]/
                     res2 = /[0-9]/
                     res3 = /[!@#$%^&*()]/
                     res4 = /[A-Z]/
                     
                     //16Aug13
                    if (document.getElementById("oldPassword").value === "") {
                        alert("Sila masukkan Kata Laluan Lama.");
                        return false;
                    } else if (document.getElementById("password").value == "") {
                        alert("Sila masukkan Kata Laluan Baru");
                        return false;
                    } else if(document.getElementById("password").value.length < 8) {                    
                        alert("Kata Laluan mesti tidak kurang 8 aksara");
                        return false;               
                    }
                    else if(!res4.test(document.getElementById("password").value)){
                        alert("Kata Laluan mesti mengandungi sekurang-kurangnya satu huruf besar");
                        return false;
                    }
                    else if(!res1.test(document.getElementById("password").value)) {
                        alert("Kata Laluan mesti mengandungi kombinasi huruf, nombor dan aksara istimewa {!@#$%^&*()}");
                        return false;
                    }                    
                    else if(!res2.test(document.getElementById("password").value)){
                        alert("Kata Laluan mesti mengandungi kombinasi huruf, nombor dan aksara istimewa {!@#$%^&*()}")
                        return false;
                    }                  
                    else if(!res3.test(document.getElementById("password").value)){
                        alert("Kata Laluan mesti mengandungi kombinasi huruf, nombor dan aksara istimewa {!@#$%^&*()}")
                        return false;                                           
                    }
                    else if(document.getElementById("password-check").value == ''){
                        alert(" Sila Masukkan Pastikan Kata Laluan");
                        return false;
                    }
                    else if(!(document.getElementById("password").value == document.getElementById("password-check").value)){
                        alert("Sila Pastikan Kedua-dua Kata Laluan adalah sama.");
                        return false;                        
                    }
                    else
                    {
                        f.action="${pageContext.request.contextPath}/pengguna/changePassword?";
                        f.submit();
                    }
                 }   
            
        </script>
    </head>
    <body>
        <div id="container">
            
            <s:form beanclass="th.stripes.action.PenggunaActionBean" class="tukar_laluan">
                 <s:errors/>
                 <s:hidden name="akaun"/>
                <div id="content">
                <div id="logo">
                    <span>
                        <img src="${pageContext.request.contextPath}/images/img/ribbon.png"/>               
                    </span>
                </div>
                <h3>
                    Tukar Kata Laluan
                </h3>
                    <p>
                        <label><font color="red">*</font>Kata Laluan Lama :</label>
                        <s:password name="oldPassword" size="20" id="oldPassword"/>
                    </p> 
                    <p>
                        <label><font color="red">*</font>Kata Laluan Baru :</label>
                        <s:password name="password" size="20" id="password"/>
                    </p>
                    <p>
                        <label><font color="red">*</font>Pastikan Kata Laluan :</label>
                        <s:password name="password2" size="20" id="password-check"/>
                    </p>
                    <p>
                        <label>&nbsp;</label>
                        <s:button name="check" value="Kemaskini" class="button green" onclick="validateForm(this.form)"/>
                    </p>
                </div>
            </s:form>
        </div>
    </body>
</html>
